package org.hackystat.sdsa.analyzer.control;

import java.util.HashMap;
import java.util.Map;

import org.hackystat.sensorbase.resource.sensordata.jaxb.Properties;
import org.hackystat.sensorbase.resource.sensordata.jaxb.Property;
import org.hackystat.sensorbase.resource.sensordata.jaxb.SensorData;

/**
 * Defines utilities method for processors.
 * 
 * @author hongbing
 *
 */
public class SensorDataUtil {
  /**
   * Converts property of the sensordata to a property map.
   * 
   * @param sensorData Sensor data.
   * @return Map of property key-value pairs.
   */
  public static Map<String, String> propMap(SensorData sensorData) {
    Map<String, String> propMap = new HashMap<String, String>();
    
    Properties props = sensorData.getProperties();
    if (props != null && props.isSetProperty()) {
       for (Property prop : props.getProperty()) {
         String key = prop.getKey().toLowerCase();
         String value = prop.getValue();
         propMap.put(key, value);
       }
    }

    return propMap;
  }
}
